/*replication materials for Timothy Hellwig, "Balancing Demands: The World Economy and the Composition of POlicy Preferences," THE JOURNAL OF POLITICS, Vol. 76, No. 1, January 2014, Pp. 1-14.*/
/*file 1 of 2: provides code to produce estimates reported in Table 1*/
version 11.2
set mem 100m
set matsize 200
set more off
use \ZA4700_F1.dta, replace
/*
NOTE: the below code is to be run on 
ZA4700: International Social Survey Programme 2006 (Role of Government IV)
the datafile can be downloaded from http://www.issp.org/
*/
keep if V3a==36 | V3a==124 | V3a==208 | V3a==246 | V3a==250 | V3a==276 | V3a==372 | V3a==392 | V3a==528 | V3a==554 | V3a==578 | V3a==620 | V3a==724 | V3a== 752 | V3a==756 | V3a==826 | V3a==840
gen sample = 0
recode sample *=1 if V3a==36 | V3a==124 | V3a==208 | V3a==246 | V3a==250 | V3a==276 | V3a==372 | V3a==392 | V3a==528 | V3a==554 | V3a==578 | V3a==620 | V3a==724 | V3a== 752 | V3a==756 | V3a==826 | V3a==840

/*creating variables*/
gen grjob = V25
recode grjob 1=4 2=3 3=2 4=1 *=.
gen grprices = V26
recode grprices 1=4 2=3 3=2 4=1 *=.
gen grhealth = V27
recode grhealth 1=4 2=3 3=2 4=1 *=.
gen groldage = V28 
recode groldage 1=4 2=3 3=2 4=1 *=.
gen grindust = V29
recode grindust 1=4 2=3 3=2 4=1 *=.
gen grune = V30
recode grune 1=4 2=3 3=2 4=1 *=.
gen grredist = V31
recode grredist 1=4 2=3 3=2 4=1 *=.
gen grstud = V32
recode grstud 1=4 2=3 3=2 4=1 *=.
gen grhouse = V33
recode grhouse 1=4 2=3 3=2 4=1 *=.
gen grenv = V34
recode grenv 1=4 2=3 3=2 4=1 *=.
gen interest = V44
recode interest 1=4 2=3 3=2 4=1 5=0
gen polunder = V47
recode polunder 1=2 2=1 3=0 4=-1 5=-2 .=0
gen btrinf = V48
recode btrinf 1=0 2=1 3=2 4=3 5=4 .=2
gen subjknow = (polunder + btrinf)/2
gen female = SEX
recode female 1=0 2=1
gen age = AGE
gen age1534 = age
recode age1534 15/34=1 *=0
gen age3549 = age
recode age3549 34/49=1 *=0
gen age5064 = age
recode age5064 50/64=1 *=0
gen age65plus = age
recode age65plus 65/max=1 *=0
gen unempl = WRKST
recode unempl 5=1 *=0
gen educ = DEGREE
gen tradsctr = ISCO88
recode tradsctr 1221=1 1311=1 3212=1 3213=1 6000=1 6100=1 6110=1 6111=1 6112=1 6114=1 6120=1 6121=1 6122=1 6123=1 6124=1 6129=1 6131=1 6140=1 6141=1 6142=1 6150/6154=1 8330=1 8331=1 9200=1 9210=1 9211=1 9212=1 9213=1 2147=1 3117=1 7111=1 8110/8113=1 9311=1 7410/7416=1 8270/8279=1 7332=1 7346=1 7430/7437=1 7440/7442=1 8260/8266=1 8269=1 7331=1 7420/7423=1 8140/8143=1 8240=1 8253=1 7340/7345=1 8250/8252=1 2146=1 2212=1 3116=1 8150/8155=1 8159=1 8220=1 8221=1 8229=1 8230/8232=1 7113=1 7320/7324=1 8130=1 8131=1 8139=1 8212=1 7210=1 7211=1 7310=1 7500=1 7510=1 8120/8124=1 8210=1 8223=1 7311=1 2143=1 2144=1 3113=1 3115=1 7220=1 7221=1 7222=1 7224=1 8281=1 8282=1 *=0
gen lparty = PARTY_LR
recode lparty 1=1 2=1 *=0
gen rparty = PARTY_LR
recode rparty 4=1 5=1 *=0
gen imports = V3a
recode imports 36=14.26 124=23.14 756=38.96 276=25.01 208=36.25 724=20.23 246=30.39 250=22.45 826=20.98 372=34.65 392=11.12 528=52.87 578=21.16 554=20.94 620=22.67 752=31.49 840=11.09
gen lnimports = ln(imports)
gen exports = V3a
recode exports 36=13.26 124=26.51 756=41.10 276=31.25 208=39.92 724=13.50 246=33.87 250=20.64 826=16.31 372=58.74 392=12.83 528=59.05 578=39.56 554=17.31 620=14.14 752=36.91 840=6.00
gen lnexports = ln(exports)
/*standardizing income*/
gen ausinc  = 0
recode ausinc *=1 if AU_INC<=23400 & V3a==36
recode ausinc *=2 if AU_INC>23400 & AU_INC<=39000 & V3a==36
recode ausinc *=3 if AU_INC>39000 & AU_INC<=65000 & V3a==36
recode ausinc *=4 if AU_INC>65000 & AU_INC<=91000 & V3a==36
recode ausinc *=5 if AU_INC>91000 & V3a==36
recode ausinc *=3 if AU_INC==. & V3a==36
gen caninc  = 0
recode caninc *=1 if CA_INC<=20000 & V3a==124
recode caninc *=2 if CA_INC>20000 & CA_INC<=40000 & V3a==124
recode caninc *=3 if CA_INC>40000 & CA_INC<=60000 & V3a==124
recode caninc *=4 if CA_INC>60000 & CA_INC<=80000 & V3a==124
recode caninc *=5 if CA_INC>80000 & V3a==124
recode caninc *=3 if CA_INC==. & V3a==124
gen cheinc  = 0
recode cheinc *=1 if CH_INC<=3600 & V3a==756
recode cheinc *=2 if CH_INC>3600 & CH_INC<=5000 & V3a==756
recode cheinc *=3 if CH_INC>5000 & CH_INC<=6700 & V3a==756
recode cheinc *=4 if CH_INC>6700 & CH_INC<=9000 & V3a==756
recode cheinc *=5 if CH_INC>9000 & V3a==756
recode cheinc *=3 if CH_INC==. & V3a==756
gen deuinc  = 0
recode deuinc *=1 if DE_INC<=1140 & V3a==276
recode deuinc *=2 if DE_INC>1140 & DE_INC<=1589 & V3a==276
recode deuinc *=3 if DE_INC>1589 & DE_INC<=2120 & V3a==276
recode deuinc *=4 if DE_INC>2120 & DE_INC<=2950 & V3a==276
recode deuinc *=5 if DE_INC>2950 & V3a==276
recode deuinc *=3 if DE_INC==. & V3a==276
gen deninc  = 0
recode deninc *=1 if DK_INC<=175000 & V3a==208
recode deninc *=2 if DK_INC>175000 & DK_INC<=350000 & V3a==208
recode deninc *=3 if DK_INC>350000 & DK_INC<=550000 & V3a==208
recode deninc *=4 if DK_INC>550000 & DK_INC<=650000 & V3a==208
recode deninc *=5 if DK_INC>650000 & V3a==208
recode deninc *=3 if DK_INC==. & V3a==208
gen espinc  = 0
recode espinc *=1 if ES_INC<=750 & V3a==724
recode espinc *=2 if ES_INC>750 & ES_INC<=1050 & V3a==724
recode espinc *=3 if ES_INC>1050 & ES_INC<=1500 & V3a==724
recode espinc *=4 if ES_INC>1500 & ES_INC<=2100 & V3a==724
recode espinc *=5 if ES_INC>2100 & V3a==724
recode espinc *=3 if ES_INC==. & V3a==724
gen fininc  = 0
recode fininc *=1 if FI_INC<=1600 & V3a==246
recode fininc *=2 if FI_INC>1600 & FI_INC<=2530 & V3a==246
recode fininc *=3 if FI_INC>2530 & FI_INC<=3650 & V3a==246
recode fininc *=4 if FI_INC>3650 & FI_INC<=4900 & V3a==246
recode fininc *=5 if FI_INC>4900 & V3a==246
recode fininc *=3 if FI_INC==. & V3a==246
gen frainc  = 0
recode frainc *=1 if FR_INC<=1450 & V3a==250
recode frainc *=2 if FR_INC>1450 & FR_INC<=2050 & V3a==250
recode frainc *=3 if FR_INC>2050 & FR_INC<=2750 & V3a==250
recode frainc *=4 if FR_INC>2750 & FR_INC<=4150 & V3a==250
recode frainc *=5 if FR_INC>4150 & V3a==250
recode frainc *=3 if FR_INC==. & V3a==250
gen gbrinc  = 0
recode gbrinc *=1 if GB_INC<=9000 & V3a==826
recode gbrinc *=2 if GB_INC>9000 & GB_INC<=16500 & V3a==826
recode gbrinc *=3 if GB_INC>16500 & GB_INC<=27500 & V3a==826
recode gbrinc *=4 if GB_INC>27500 & GB_INC<=41000 & V3a==826
recode gbrinc *=5 if GB_INC>41000 & V3a==826
recode gbrinc *=3 if GB_INC==. & V3a==826
gen ireinc  = 0
recode ireinc *=1 if IE_INC<=10750 & V3a==372
recode ireinc *=2 if IE_INC>10750 & IE_INC<=21000 & V3a==372
recode ireinc *=3 if IE_INC>21000 & IE_INC<=33000 & V3a==372
recode ireinc *=4 if IE_INC>33000 & IE_INC<=48000 & V3a==372
recode ireinc *=5 if IE_INC>48000 & V3a==372
recode ireinc *=3 if IE_INC==. & V3a==372
gen jpninc  = 0
recode jpninc *=1 if JP_INC<=2500000 & V3a==392
recode jpninc *=2 if JP_INC>2500000 & JP_INC<=3500000 & V3a==392
recode jpninc *=3 if JP_INC>3500000 & JP_INC<=6500000 & V3a==392
recode jpninc *=4 if JP_INC>6500000 & JP_INC<=8500000 & V3a==392
recode jpninc *=5 if JP_INC>8500000 & V3a==392
recode jpninc *=3 if JP_INC==. & V3a==392
gen netinc  = 0
recode netinc *=1 if NL_INC<=1500 & V3a==528
recode netinc *=2 if NL_INC>1500 & NL_INC<=1950 & V3a==528
recode netinc *=3 if NL_INC>1950 & NL_INC<=2750 & V3a==528
recode netinc *=4 if NL_INC>2750 & NL_INC<=3550 & V3a==528
recode netinc *=5 if NL_INC>3550 & V3a==528
recode netinc *=3 if NL_INC==. & V3a==528
gen norinc  = 0
recode norinc *=1 if NO_INC<=259000 & V3a==578
recode norinc *=2 if NO_INC>259000 & NO_INC<=398000 & V3a==578
recode norinc *=3 if NO_INC>398000 & NO_INC<=590000 & V3a==578
recode norinc *=4 if NO_INC>560000 & NO_INC<=745000 & V3a==578
recode norinc *=5 if NO_INC>745000 & V3a==578
recode norinc *=3 if NO_INC==. & V3a==578
gen nzdinc  = 0
recode nzdinc *=1 if NZ_INC<=22500 & V3a==554
recode nzdinc *=2 if NZ_INC>22500 & NZ_INC<=35000 & V3a==554
recode nzdinc *=3 if NZ_INC>35000 & NZ_INC<=65000 & V3a==554
recode nzdinc *=4 if NZ_INC>65000 & NZ_INC<=90000 & V3a==554
recode nzdinc *=5 if NZ_INC>90000 & V3a==554
recode nzdinc *=3 if NZ_INC==. & V3a==554
gen prtinc  = 0
recode prtinc *=1 if PT_INC==175 & V3a==620
recode prtinc *=2 if PT_INC==425 & V3a==620
recode prtinc *=3 if PT_INC==650 & V3a==620
recode prtinc *=4 if PT_INC==1150 & V3a==620
recode prtinc *=5 if PT_INC>1150 & V3a==620
recode prtinc *=3 if PT_INC==. & V3a==620
gen sweinc  = 0
recode sweinc *=1 if SE_INC<=19000 & V3a==752
recode sweinc *=2 if SE_INC>19000 & SE_INC<=27000 & V3a==752
recode sweinc *=3 if SE_INC>27000 & SE_INC<=38000 & V3a==752
recode sweinc *=4 if SE_INC>38000 & SE_INC<=49000 & V3a==752
recode sweinc *=5 if SE_INC>49000 & V3a==752
recode sweinc *=3 if SE_INC==. & V3a==752
gen usainc  = 0
recode usainc *=1 if US_INC<=16750 & V3a==840
recode usainc *=2 if US_INC>16750 & US_INC<=27500 & V3a==840
recode usainc *=3 if US_INC>27500 & US_INC<=45000 & V3a==840
recode usainc *=4 if US_INC>45000 & US_INC<=67500 & V3a==840
recode usainc *=5 if US_INC>67500 & V3a==840
recode usainc *=3 if US_INC==. & V3a==840
gen incquints = ausinc + caninc + cheinc + deuinc + deninc + espinc + fininc + frainc + gbrinc + ireinc + jpninc + netinc + norinc + nzdinc + prtinc + sweinc + usainc
recode incquints 0=.
gen inclo3 = incquints
recode inclo3 1=1 2=1 .=. *=0
gen inchi3 = incquints
recode inchi3 5=1 .=. *=0
gen blucoll = ISCO88
recode blucoll 1221/1222=1 1311/1312=1 6100/8900=1 9200/max=1 *=0
/*copartisanship*/
gen copartpm = 0
recode copartpm *=1 if AU_PRTY==1 | CA_PRTY==1 | DK_PRTY==7 | FI_PRTY==2 | FR_PRTY==6 | DE_PRTY==1 | IE_PRTY==1 | JP_PRTY==1 | NL_PRTY==1 | NZ_PRTY==4 | NO_PRTY==2 | PT_PRTY==9 | ES_PRTY==1 | SE_PRTY==6 | CH_PRTY==5 | GB_PRTY==2 | US_PRTY==5 | US_PRTY==6 | US_PRTY==7
gen copartgv = copartpm
recode copartgv *=1 if AU_PRTY==3 | DK_PRTY==3 | FI_PRTY==1 | DE_PRTY==2 | IE_PRTY==5 | NL_PRTY==3 | NL_PRTY==7 | NZ_PRTY==7 | NO_PRTY==7 | NO_PRTY==6 | CH_PRTY==4 | CH_PRTY==1 | CH_PRTY==6
gen gbc = blucoll
recode gbc 1=1 0=-1
gen gloser = (gbc*incquints)/5 
/*macro variables*/
/*kof globalization econ flows*/
gen koff= V3a
recode koff 36=.5469 124=.7616 208=.8773 246=.8103 250=.6465 276=.6299 372=.7725 392=.2694 528=.9521 554=.6616 578=.8064 620=.765 724=.7442 752=.8815 756=.9041 826=.7156 840=.4079
/*kof globalization econ restrictions 2005*/
gen kofr = V3a
recode kofr 36=.8087 124=.8255 208=.8896 246=.9259 250=.8962 276=.8717 372=.9471 392=.8217 528=.89 554=.8859 578=.6977 620=.8997 724=.8651 752=.9071 756=.7637 826=.9046 840=.8459
gen kofecon = V3a
recode kofecon 36=.6813 124=.7909 208=.8848 246=.867 250=.7735 276=.7446 372=.8601 392=.541 528=.9221 554=.7548 578=.7592 620=.8297 724=.8044 752=.8945 756=.8369 826=.7943 840=.6357
gen federal = 0
recode federal *=1 if V3a==36 | V3a==124 | V3a==276 | V3a==756 | V3a==840
gen ethnic = V3a
recode ethnic 36=.0929 124=.7124 208=.0819 246=.1315 250=.1032 276=.1682 372=.1206 392=.0119 528=.1054 554=.3969 578=.0586 620=.0468 724=.4165 752=.06 756=90.41 826=.1211 840=.4601
gen protsnt = V3a
recode protsnt 36=23.5 124=29.6 208=95.2 246=93.1 250=2.4 276=46.4 372=1.1 392=.9 528=42.4 554=37.9 578=97.8 620=1.1 724=.1 752=68.4 756=43.2 826=16.1 840=43.6
gen cathpct = V3a
recode cathpct 36=29.6 124=46.6 208=.6 246=.1 250=76.4 276=35 372=95.3 392=.6 528=42.6 554=18.7 578=.3 620=94.1 724=96.9 752=1.4 756=52.8 826=13.1 840=30
gen catholic = cathpct/100
gen pwtpop = V3a
recode pwtpop 36=20232.346 124=32386.378 208=5432.335 246=5223.442 250=62911.523 276=82431.39 372=4015.676 392=127537.189 528=16407.491 554=4048.224 578=4593.041 620=10566.212 724=40341.462 752=9001.774 756=7489.37 826=60441.457 840=295583.436
gen lnpop = ln(pwtpop)
gen pwtcgdp = V3a
recode pwtcgdp 36=34323.38 124=34590.48 208=32162.12 246=29761.46 250=28779.30 276=29547.73 372=38659.30 392=29780.30 528=32638.07 554=24551.48 578=45694.47 620=19561.75 724=29150.45 752=30657.45 756=35444.13 826=30275.79 840=41870.41
gen lncgdp = ln(pwtcgdp)
gen pwtopenc = V3a
recode pwtopenc 36=42.08 124=71.92 208=92.84 246=78.07 250=52.98 276=76.75 372=151.44 392=27.28 528=131.67 554=58.15 578=72.8 620=65.60 724=56.69 752=89.73 756=91.12 826=56.6 840=26.93
gen lnopenc = ln(pwtopenc)
gen pct65 = V3a
recode pct65 36=12.8 124=14.1 208=14.9 246=15.9 250=16.1 276=18.9 372=11.6 392=19.6 528=14.2 554=12.1 578=14.6 620=17.1 724=17.5 752=17.5 756=15.4 826=15.8 840=12.4
gen unerate = V3a
recode unerate 36=5.1 124=6.8 208=5.6 246=8 250=9.8 276=9.5 372=4.2 392=4.3 528=5 554=4 578=4.2 620=7.4 724=9.1 752=5.2 756=3.7 826=4.7 840=5.2
gen welfare = V3a
recode welfare 36=17.11 124=16.49 208=27.08 246=26.10 250=29.17 276=26.75 372=16.73 392=18.58 528=20.88 554=18.55 578=21.64 620=23.10 724=21.24 752=29.43 756=20.26 826=21.29 840=15.91
gen wdicap05 = V3a
gen wdicap3yr = V3a
recode wdicap05 36=11.11 124=5.49 208=10.91 246=6.47 250=6.16 276=3.84 372=69.25 392=1.29 528=32.61 554=4.15 578=9.14 620=3.98 724=8.43 752=7.47 756=26.73 826=13.53 840=6.17
recode wdicap3yr 36=9.52 124=19.55 208=12.77 246=7.62 250=7.85 276=5.49 372=26.42 392=25.33 528=13.12 554=12.68 578=15.30 620=5.76 724=7.19 752=6.63 756=14.21 826=15.91 840=15.47
gen lnwdicap05 = ln(wdicap05)
gen lnwdicap3yr = ln(wdicap3yr)
/*pwt growth*/
gen growtht1 = V3a
recode growtht1 36=1.99 124=2.804 208=2.068 246=3.661 250=2.121 276=1.078 372=2.333 392=2.685 528=1.651 554=2.579 578=4.118 620=1.07 724=3.575 752=4.101 756=1.988 826=3.108 840=3.037
gen gini_grosst1 = V3a
recode gini_grosst1 36=43.942 124=43.333 208=45.426 246=48.646 250=40.914 276=52.24 372=41.08 392=40.508 528=42.442 554=45.948 578=48.127 620=61.009 724=39.364 752=45.068 756=50.178 826=48.093 840=47.461
gen gini_nett1 = V3a
recode gini_nett1 36=31.571 124=31.8 208=22.8 246=25.2 250=27.645 276=27.8 372=31.75 392=34.209 528=27.221 554=32.925 578=25.6 620=37.248 724=31.575 752=23.125 756=31.065 826=34.5 840=37.2
gen transfer = gini_grosst1 - gini_nett1

/*factor analysis*/
factor grjob grprices grhealth groldage grindust grune grredist grstud grhouse grenv, pcf factors(2) mine(.98)
rotate
predict f1 f2, r
gen prefall = ((grjob + grprices + grhealth + groldage + grindust + grune + grredist + grstud + grhouse + grenv)/10)-2.5
sum f1 f2 prefall

/*TABLE 1 RUNS*/
xtmixed prefall koff growtht1 lncgdp trans ethnic catholic federal lparty rparty copartgv gloser polunder educ female age3549 age5064 age65plus || V3a:, mle var
xtmixed f1 koff growtht1 lncgdp trans ethnic catholic federal lparty rparty copartgv gloser polunder educ female age3549 age5064 age65plus || V3a:, mle var
xtmixed f2 koff growtht1 lncgdp trans ethnic catholic federal lparty rparty copartgv gloser polunder educ female age3549 age5064 age65plus || V3a:, mle var

